package com.example.BlockChain.controller;

import com.example.BlockChain.entity.JSONObject;
import com.example.BlockChain.entity.TUser;
import com.example.BlockChain.entity.Timing;
import com.example.BlockChain.service.BlockService;
import com.example.BlockChain.service.TimingService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
public class TimingController {
    @Resource
    private TimingService timingService;
    @Resource
    private BlockService blockService;

    /**
     * 配送员接收订单
     *
     * @return ResponseEntity
     */
    @RequestMapping(value = "/deliveryAcceptOrder", method = RequestMethod.POST)
    public ResponseEntity<JSONObject> deliveryAcceptOrder(@RequestBody Timing timing) {
        JSONObject jo = new JSONObject();

        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String acceptTime = now.format(formatter);  // 格式化为字符串

        //更新接受订单的时间数据
        timing.setRiderAcceptTime(acceptTime);
        timingService.updateAcceptTime(timing);
        jo.setO(timing);

        String orderid=timing.getOrderId();
        //修改operation_type=4(表示配送员接单)
        blockService.updateOperationType4(orderid);

        jo.setCode("200");
        jo.setMsg("数据更新成功");
        return new ResponseEntity<>(jo, HttpStatus.OK);

    }
}



